package com.kaishengit.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Locale;

public class DataUtil {
	private static DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public static String getNow(){
		Date date = new Date();
		DateFormat df = new SimpleDateFormat("EE yyyy年MM月dd日 ", Locale.CHINA); 
		return df.format(date);
	}
	
	public static String noteStarttime(String date) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
		 long  date_long1 = sdf.parse(date).getTime();
		 System.out.println(date_long1);
		 DateFormat df4 = new SimpleDateFormat("EE yyyy年MM月dd日 ", Locale.CHINA); 
		 return df4.format(date_long1);
	}
	private static int getMondayPlus() {  
        Calendar cd = Calendar.getInstance();  
        // 获得今天是一周的第几天，星期日是第一天，星期二是第二天......  
        int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK)-1; 
        System.out.println(dayOfWeek);//因为按中国礼拜一作为第一天所以这里减1  
        if (dayOfWeek == 1) {  
            return 0;  
        } else {  
            return 1 - dayOfWeek;  
        }  
    }  
	//获得今天的开始时间
	public static String getTodayStartTime(){
		 Calendar todayStart = Calendar.getInstance();  
	     todayStart.set(Calendar.HOUR_OF_DAY,0);  
	     todayStart.set(Calendar.MINUTE, 0);  
	     todayStart.set(Calendar.SECOND, 0);  
	     todayStart.set(Calendar.MILLISECOND,0); 
	     Date date = todayStart.getTime();
	    
	     return df2.format(date);
	}
	//获得今天的结束时间
	public static String getTodayEndTime(){
		 Calendar todayEnd = Calendar.getInstance();  
	     todayEnd.set(Calendar.HOUR_OF_DAY,24);  
	     todayEnd.set(Calendar.MINUTE, 0);  
	     todayEnd.set(Calendar.SECOND, 0);  
	     todayEnd.set(Calendar.MILLISECOND,0); 
	     Date date2 = todayEnd.getTime();
	     return df2.format(date2);
	}
	//获得明天的开始时间
	public static String getTomorrowStartTime(){
		 Date date3=new Date();//取时间
	     Calendar tomorrowStart = new GregorianCalendar();
	     tomorrowStart.setTime(date3);
	     tomorrowStart.add(tomorrowStart.DATE,1);
	     tomorrowStart.set(Calendar.HOUR_OF_DAY,0);  
	     tomorrowStart.set(Calendar.MINUTE, 0);  
	     tomorrowStart.set(Calendar.SECOND, 0);  
	     tomorrowStart.set(Calendar.MILLISECOND,0);
	     Date date4 = tomorrowStart.getTime();
	     return df2.format(date4);
	}
	
	//获得明天的结束时间
	public static String getTomorrowEndTime(){
		 Date date3=new Date();//取时间
	     Calendar tomorrowStart = new GregorianCalendar();
	     tomorrowStart.setTime(date3);
	     tomorrowStart.add(tomorrowStart.DATE,1);
	     tomorrowStart.set(Calendar.HOUR_OF_DAY,24);  
	     tomorrowStart.set(Calendar.MINUTE, 0);  
	     tomorrowStart.set(Calendar.SECOND, 0);  
	     tomorrowStart.set(Calendar.MILLISECOND,0);
	     Date date4 = tomorrowStart.getTime();
	     return df2.format(date4);
	}
	
	//获得这周的开始时间
	public static String getThisweekStartTime(){
		 int mondayPlus =getMondayPlus();  
	     GregorianCalendar currentDate = new GregorianCalendar();  
	     currentDate.add(GregorianCalendar.DATE, mondayPlus);
	     currentDate.set(Calendar.HOUR_OF_DAY,0);  
	     currentDate.set(Calendar.MINUTE,0);  
	     currentDate.set(Calendar.SECOND,0);  
	     currentDate.set(Calendar.MILLISECOND,0);
	     Date monday = currentDate.getTime();
	     return df2.format(monday);
	}
	public static String getThisweekEndTime(){
		int mondayPlus2 = getMondayPlus();  
	     GregorianCalendar currentDate2 = new GregorianCalendar();  
	     currentDate2.add(GregorianCalendar.DATE, mondayPlus2+6);  
	     currentDate2.set(Calendar.HOUR_OF_DAY,24);  
	     currentDate2.set(Calendar.MINUTE,0);  
	     currentDate2.set(Calendar.SECOND,0);  
	     currentDate2.set(Calendar.MILLISECOND,0);
	     Date monday2 = currentDate2.getTime();      
	     String preMonday = df2.format(monday2);
	     return preMonday;
	}
	//获得下周的开始时间 和结束时间
	public static String getNextweekStartTime(){
		 int mondayPlus3s =getMondayPlus();  
	     GregorianCalendar currentDate3 = new GregorianCalendar();  
	     currentDate3.add(GregorianCalendar.DATE, mondayPlus3s+7); 
	     currentDate3.set(Calendar.HOUR_OF_DAY,0);  
	     currentDate3.set(Calendar.MINUTE,0);  
	     currentDate3.set(Calendar.SECOND,0);  
	     currentDate3.set(Calendar.MILLISECOND,0);  
	     Date monday3 = currentDate3.getTime(); 
	     String preMonday1 = df2.format(monday3);
	     return preMonday1;
	}
	public static String getNextweekEndTime(){
		 int mondayPlus4s =getMondayPlus(); 
	     GregorianCalendar currentDate4 = new GregorianCalendar();  
	     currentDate4.add(GregorianCalendar.DATE, mondayPlus4s+13); 
	     currentDate4.set(Calendar.HOUR_OF_DAY,24);  
	     currentDate4.set(Calendar.MINUTE,0);  
	     currentDate4.set(Calendar.SECOND,0);  
	     currentDate4.set(Calendar.MILLISECOND,0);  
	     Date monday4 = currentDate4.getTime();  
	     String preMonday2 = df2.format(monday4);
	     return preMonday2;
	}
	public static String  getJutiStartTime(String time){
		Calendar date=Calendar.getInstance(); 
		String[] str = time.split("/");
		int year = Integer.valueOf(str[2]);
		int month = Integer.valueOf(str[0]);
		int day = Integer.valueOf(str[1]);
		date.set(year,month-1,day);
        date.set(Calendar.HOUR_OF_DAY,0); 
        date.set(Calendar.MINUTE,0); 
        date.set(Calendar.SECOND,0); 
        date.set(Calendar.MILLISECOND,0);  
        Date monday4 = date.getTime();
        return df2.format(monday4);

	}
	public static String  getJutiEndTime(String time){
		Calendar date=Calendar.getInstance(); 
		String[] str = time.split("/");
		int year = Integer.valueOf(str[2]);
		int month = Integer.valueOf(str[0]);
		int day = Integer.valueOf(str[1]);
		date.set(year,month-1,day);
        date.set(Calendar.HOUR_OF_DAY,24); 
        date.set(Calendar.MINUTE,0); 
        date.set(Calendar.SECOND,0); 
        date.set(Calendar.MILLISECOND,0);  
        Date monday4 = date.getTime();
        return df2.format(monday4);
	}
	//获得具体的时间 到页面进行分类的
	public static String getDataType(String starttime,String endtime) throws ParseException{
		//获得今天结束的毫秒数
		long todayStartTime = df2.parse(getTodayStartTime()).getTime();
		long todayEndTime = df2.parse(getTodayEndTime()).getTime();
		//获得明天结束的毫秒数
		long tomorrowEndTime = df2.parse(getTomorrowEndTime()).getTime();
		//获得这周结束的时间的毫秒数
		long thisweekEndTime = df2.parse(getThisweekEndTime()).getTime();
		//获得下周结束的时间
		long nextweekEndTime = df2.parse(getNextweekEndTime()).getTime();
		long end = 0l;
		long start = df2.parse(starttime).getTime();
		end = df2.parse(endtime).getTime();
		if(end == todayEndTime){
			return "today";
		}else if(end ==tomorrowEndTime ){
			return "tomorrow";
		}else if(end == thisweekEndTime){
			return "thisweek";
		}else if(end == nextweekEndTime){
			return "nextweek";
		}else if(start == nextweekEndTime){
			return "later";
		}else if(tomorrowEndTime<end&&end<=thisweekEndTime){
			return "thisweek";
		}else if(thisweekEndTime<end &&end<=nextweekEndTime){
			return "nextweek";
		}else if(end<=todayStartTime){
			return "overdue";
		}else{
			return "null";
		}
			
		}
}
